package ucuserslogic

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/common/utils"
	"navi-mumbai/common/xerr"

	"navi-mumbai/app/rpc/usercenter/internal/svc"
	"navi-mumbai/app/rpc/usercenter/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserNotifyMsgStatLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserNotifyMsgStatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserNotifyMsgStatLogic {
	return &GetUserNotifyMsgStatLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 定时刷新新消息数量
func (l *GetUserNotifyMsgStatLogic) GetUserNotifyMsgStat(in *pb.GetUserNotifyMsgStatReq) (*pb.GetUserNotifyMsgStatResp, error) {
	defer utils.RecoverPanic()

	var err error
	var uns *usercenter.UserNotifyMsgStat
	uns, err = l.svcCtx.UserNotifyMsgStatModel.FindOne(l.ctx, in.Uid)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	var resp pb.GetUserNotifyMsgStatResp
	resp.Total = uns.Total
	resp.NotRead = uns.NotRead
	return &resp, nil
}
